package tinyinventor;

import codeblocks.Block;
import codeblocks.LinkRule;
import codeblocks.BlockConnector;

/**
 * LinkRule that prevents constants from linking as procedure parameters and prevents parameters
 * from linking as constants in other code.
 */
public class ParamProcedureRule implements LinkRule {

    public boolean canLink(Block block1, Block block2, BlockConnector socket1, BlockConnector socket2) {
    	
    	switch (socket1.getPositionType()) {
        case BOTTOM:
        case TOP:
            return true; // we're only checking params, so ignore top and bottom connectors
        }
        
        //System.out.println("block1 decl? " + block1.isProcedureDeclBlock() + ", block2 decl? " + block2.isProcedureDeclBlock());
        //System.out.println("block1 param? " + block1.isProcedureParamBlock() + ", block2 param? " + block2.isProcedureParamBlock());
        
        if(block1.isProcedureDeclBlock()) {
        	return block2.isProcedureParamBlock();
        }
        
        if(block1.isProcedureParamBlock()) {
        	return block2.isProcedureDeclBlock();
        }
        
        if(block2.isProcedureDeclBlock()) {
        	return block1.isProcedureParamBlock();
        }
        
        if(block2.isProcedureParamBlock()) {
        	return block1.isProcedureDeclBlock();
        }

        return true;
        
    }

    public boolean isMandatory() {
        return true;
    }
}
